﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SQLite;
using NHibernate;
using NHibernate.Cfg;
using OBSwindles;
using System.Collections;

namespace DASwindles
{
    public class CustomerData : IDataManager
    {
        public CustomerData()
        {
            
        }
        #region IDataManager Members
        public IList getDetails()
        {
            
            IList customerList = null;
            ISession session = DAHelper.getSession();
            customerList = session.CreateCriteria(typeof(Customer)).List();
            return customerList;
        }

        public object getDetails_ByID(int p_ID)
        {
            IList customerList = null;
            ISession session = DAHelper.getSession();
            customerList = session.CreateCriteria(typeof(Customer)).List();
            if (customerList != null)
            {
                for (int i = 0; i < customerList.Count; i++)
                {
                    Customer customer = (Customer)customerList[i];
                    if (customer.CustomerID == p_ID)
                    {
                        return customer;
                    }
                }

            }
            return null;
        }

        public void updateDetails(object p_Object)
        {
            ISession session = DAHelper.getSession();
            session.Update(p_Object);
            
        }

        public int insertDetails(object p_Object)
        {
            ISession session = DAHelper.getSession();
            session.Save(p_Object);
            return ((Customer)p_Object).CustomerID;
        }
        #endregion
    }
}
